#include "Projectile.h"

CProjectile::CProjectile(void)
: m_bActive(false)
, thePosition(0, 0, 0)
, theDirection(0, 0, 0)
{
}

CProjectile::~CProjectile(void)
{
}

// Update the status of this projectile
void CProjectile::Update(void)
{
	if (m_bActive == false)
		return;

	// Update TimeLife of projectile. Set to inactive if too long

	// Update Position
	thePosition.Set(	thePosition.x + theDirection.x, 
						thePosition.y + theDirection.y, 
						thePosition.z + theDirection.z);

	// Check for collision. if yes, then set to inactive

	// Check for out of bounds. if yes, then set to inactive

	// Draw the projectile
	// if got collision....draw collision effects

	// else draw projectile travelling


	float size = 1.0f;
	glPushMatrix();
		glTranslatef(thePosition.x, thePosition.y, thePosition.z);
		glRotatef( atan(theDirection.x / theDirection.z)*180.0f/3.142f , 0, 1, 0);

			glBegin(GL_QUADS);
			// FRONT
			glVertex3f(-size, size, size);
			glVertex3f(size, size, size);
			glVertex3f(size, -size, size);
			glVertex3f(-size, -size, size);

			// BACK
			glVertex3f(-size, -size, -size);
			glVertex3f(size, -size, -size);
			glVertex3f(size, size, -size);
			glVertex3f(-size, size, -size);

			// LEFT
			glVertex3f(-size, size, -size);
			glVertex3f(-size, size, size);
			glVertex3f(-size, -size, size);
			glVertex3f(-size, -size, -size);

			// RIGHT
			glVertex3f(size, -size, -size);
			glVertex3f(size, -size, size);
			glVertex3f(size, size, size);
			glVertex3f(size, size, -size);

			// TOP
			glVertex3f(-size, size, -size);
			glVertex3f(size, size, -size);
			glVertex3f(size, size, size);
			glVertex3f(-size, size, size);

			// BOTTOM
			glVertex3f(-size, -size, size);
			glVertex3f(size, -size, size);
			glVertex3f(size, -size, -size);
			glVertex3f(-size, -size, -size);
			glEnd();
	glPopMatrix();
}

// Activate the projectile. true == active, false == inactive
void CProjectile::SetActivate(bool m_bActivate)
{
	if (m_bActivate == true)
		m_bActive = true;
	else
		m_bActive = false;
}

// get status of the projectile. true == active, false == inactive
bool CProjectile::GetStatus(void)
{
	return m_bActive;
}

// Set the position of the projectile
void CProjectile::SetPosition(Vector3D theNewPosition)
{
	thePosition.Set( theNewPosition.x, theNewPosition.y, theNewPosition.z);
}

// Set the direction of the projectile
void CProjectile::SetDirection(Vector3D theNewDirection)
{
	theDirection.Set( theNewDirection.x, theNewDirection.y, theNewDirection.z);
}
